using Godot;
using Godot.Collections;
using Godot.NativeInterop;
using System;
using System.Runtime;

public partial class ActorChooseView : WindowBase
{
    Button finishBtn = new Button();
    ItemList actorList = new ItemList();

    Array<ActorHero> heroList = new Array<ActorHero>();
    public override void init()
    {
        base.init();
        finishBtn = GetNode<Button>("Button");
        finishBtn.Pressed += OnPressedFinishBtn;
        actorList = GetNode<ItemList>("ItemList");
        actorList.ItemClicked += OnItemClick;
    }

    private void OnItemClick(long index, Vector2 atPosition, long mouseButtonIndex)
    {
        ActorModel.getInstance().AddFightHero(heroList[(int)index]);
        EventParams param = new EventParams();
        param.paramDict["actid"] = heroList[(int)index].actId;
        EventManager.getInstance().dispatchEvent(EventType.EVENT_TILE_MAP_CHOOSE_ITEMLIST_ITEM_CLICK, param);
    }


    public override void onShow()
    {
        base.onShow();
        actorList.Clear();
        heroList = ActorModel.getInstance().GetHeroList();

        foreach (var hero in heroList)
        {
            if (!ActorModel.getInstance().CheckHeroInFight(hero))
            {
                actorList.AddItem(hero.cName);
            }


        }


    }


    private void OnPressedFinishBtn()
    {
        //SaveAndLoadManager.getInstance().Save();
        /*CatpurePicManager.getInstance().SaveCaptureScreenShot();

        GetNode<TextureRect>("TextureRect").Texture = CatpurePicManager.getInstance().GetImageFromShotPath("2024-01-09T10-00-31");*/
    }
}
